<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
</head>
<body>
<form id="defect_table" class="layui-form" method="" action="" style="margin-top: 30px;margin-left: 200px">
    <input type="hidden" name="id">
    <!--第一个-->
    <div style="float: left;">
        <!--缺陷类型-->
        <div class="layui-form-item" >
            <label class="layui-form-label">缺陷名称：</label>
            <div class="layui-input-inline">
                <input type="text" id="defect_name" name="defect_name"   lay-verify="required|defect_name" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
            </div>
        </div>
    </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">启用状态：</label>
        <div class="layui-input-inline">
            <input type="radio" name="defect_state" value="1" title="启用" checked>
            <input type="radio" name="defect_state" value="0" title="不启用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm"type="button" lay-submit="formDemo2" lay-filter="formDemo2"style="margin-left: 50px"> 添加</button>
        </div>
    </div>
</form>
<script src="../layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','laydate','layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,laydate = layui.laydate
            ,layedit = layui.layedit
            ,layer=layui.layer
            ,form = layui.form;
        form.on('submit(formDemo2)', function(data){
            console.log(data.field);
        $.ajax({
            url:"/addType",
            type:"POST",
            dataType: "json",
            data:JSON.stringify(data.field),
            success:function (res) {
                layer.alert("添加成功");
                if (res.code == 200 ){
                    parent.layer.close(parent.layer.index);
                    console.log(res.code);
                }else if (res.code==500){
                    layer.msg(res.msg,{icon:5});
                }else if (res.code == 405){
                    layer.msg(res.msg,{icon:5});
                }
            }
        });
    });
    });
</script>


</body>
</html>